namespace Library
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;

    [ToolboxBitmap(typeof(Polygon))]
    public class Polygon : Control
    {
        private bool _bHaveAction = false;
        private string _ClickEvent = null;
        private System.Drawing.Drawing2D.DashStyle _dashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
        private string _DoubleEvent = null;
        private Color _FillColor = Color.White;
        private string _FillColorName = null;
        private FillPatternStyle _fillPattern = FillPatternStyle.Color;
        private System.Drawing.Drawing2D.HatchStyle _hatchStyle = System.Drawing.Drawing2D.HatchStyle.Cross;
        private string _heightName = null;
        private int _LineAlpha = 0xff;
        private Color _LineColor = Color.Black;
        private int _LineWidth = 2;
        private Color _newFillColor = Color.Red;
        private Color _oldFillColor = Color.DarkGray;
        private Point _p1 = new Point(10, 10);
        private Point _p2 = new Point(50, 0);
        private Point _p3 = new Point(60, 30);
        private Point _p4 = new Point(50, 60);
        private Point _p5 = new Point(20, 50);
        private Point _p6 = new Point(10, 40);
        private bool _visible = true;
        private string _visibleName = null;
        private string _widthName = null;
        private string _xName = null;
        private string _yName = null;
        private IContainer components = null;
        public bool isRuntime = false;

        public Polygon()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics graphics = pe.Graphics;
            GraphicsPath path = new GraphicsPath();
            Rectangle rectangle = new Rectangle(0, 0, base.ClientSize.Width - 1, base.ClientSize.Height - 1);
            Point[] points = new Point[] { this.p1, this.p2, this.p3, this.p4, this.p5, this.p6 };
            path.AddPolygon(points);
            Brush brush = null;
            switch (this.FillPattern)
            {
                case FillPatternStyle.Color:
                    brush = new SolidBrush(this.FillColor);
                    break;

                case FillPatternStyle.Hatch:
                    brush = new HatchBrush(this.HatchStyle, this.FillColor);
                    break;
            }
            if (brush != null)
            {
                graphics.FillPath(brush, path);
                brush.Dispose();
            }
            Pen pen = null;
            pen = new Pen(Color.FromArgb(this.LineAlpha, this.LineColor));
            pen.Width = this.LineWidth;
            pen.DashStyle = this.DashStyle;
            graphics.DrawPath(pen, path);
            if (pen != null)
            {
                pen.Dispose();
            }
            path.Dispose();
            base.OnPaint(pe);
        }

        public bool bHaveAction
        {
            get
            {
                return this._bHaveAction;
            }
            set
            {
                this._bHaveAction = value;
            }
        }

        public string ClickEvent
        {
            get
            {
                return this._ClickEvent;
            }
            set
            {
                this._ClickEvent = value;
            }
        }

        [Description("边缘风格"), Category("外观")]
        public System.Drawing.Drawing2D.DashStyle DashStyle
        {
            get
            {
                return this._dashStyle;
            }
            set
            {
                this._dashStyle = value;
                base.Invalidate();
            }
        }

        public string DoubleEvent
        {
            get
            {
                return this._DoubleEvent;
            }
            set
            {
                this._DoubleEvent = value;
            }
        }

        [Description("填充颜色"), Category("外观")]
        public Color FillColor
        {
            get
            {
                return this._FillColor;
            }
            set
            {
                this._FillColor = value;
                base.Invalidate();
            }
        }

        public string FillColorName
        {
            get
            {
                return this._FillColorName;
            }
            set
            {
                this._FillColorName = value;
            }
        }

        [Category("外观"), Description("填充图案")]
        public FillPatternStyle FillPattern
        {
            get
            {
                return this._fillPattern;
            }
            set
            {
                this._fillPattern = value;
                base.Invalidate();
            }
        }

        [Category("外观"), Description("填充风格")]
        public System.Drawing.Drawing2D.HatchStyle HatchStyle
        {
            get
            {
                return this._hatchStyle;
            }
            set
            {
                this._hatchStyle = value;
                base.Invalidate();
            }
        }

        public string heightName
        {
            get
            {
                return this._heightName;
            }
            set
            {
                this._heightName = value;
            }
        }

        [Category("行为"), Description("确定该控件是可见的还是隐藏的")]
        public bool isVisible
        {
            get
            {
                return this._visible;
            }
            set
            {
                this._visible = value;
                if (this.isRuntime)
                {
                    base.Visible = this._visible;
                }
            }
        }

        [Category("外观"), Description("线色透明值0~255")]
        public int LineAlpha
        {
            get
            {
                return this._LineAlpha;
            }
            set
            {
                this._LineAlpha = value;
                base.Invalidate();
            }
        }

        [Description("边缘线色"), Category("外观")]
        public Color LineColor
        {
            get
            {
                return this._LineColor;
            }
            set
            {
                this._LineColor = value;
                base.Invalidate();
            }
        }

        [Category("外观"), Description("边缘线宽")]
        public int LineWidth
        {
            get
            {
                return this._LineWidth;
            }
            set
            {
                this._LineWidth = value;
                base.Invalidate();
            }
        }

        public Color newFillColor
        {
            get
            {
                return this._newFillColor;
            }
            set
            {
                this._newFillColor = value;
            }
        }

        public Color oldFillColor
        {
            get
            {
                return this._oldFillColor;
            }
            set
            {
                this._oldFillColor = value;
            }
        }

        public Point p1
        {
            get
            {
                return this._p1;
            }
            set
            {
                this._p1 = value;
                base.Invalidate();
            }
        }

        public Point p2
        {
            get
            {
                return this._p2;
            }
            set
            {
                this._p2 = value;
                base.Invalidate();
            }
        }

        public Point p3
        {
            get
            {
                return this._p3;
            }
            set
            {
                this._p3 = value;
                base.Invalidate();
            }
        }

        public Point p4
        {
            get
            {
                return this._p4;
            }
            set
            {
                this._p4 = value;
                base.Invalidate();
            }
        }

        public Point p5
        {
            get
            {
                return this._p5;
            }
            set
            {
                this._p5 = value;
                base.Invalidate();
            }
        }

        public Point p6
        {
            get
            {
                return this._p6;
            }
            set
            {
                this._p6 = value;
                base.Invalidate();
            }
        }

        public string visibleName
        {
            get
            {
                return this._visibleName;
            }
            set
            {
                this._visibleName = value;
            }
        }

        public string widthName
        {
            get
            {
                return this._widthName;
            }
            set
            {
                this._widthName = value;
            }
        }

        public string xName
        {
            get
            {
                return this._xName;
            }
            set
            {
                this._xName = value;
            }
        }

        public string yName
        {
            get
            {
                return this._yName;
            }
            set
            {
                this._yName = value;
            }
        }

        public enum FillPatternStyle
        {
            Color,
            Hatch,
            None
        }
    }
}

